// Inputs into the shader:
// World-View-Projection transformations all combined into a single matrix
float4x4 WVP;

// Vertex-shader input
struct VSInput
{
	float4 Position : POSITION0;
};

// Vertex-shader output
// We ALWAYS output a position (with semantic POSITION0) from a vertex shader 
// because it lets the graphics hardware know where to draw the triangles on 
// the screen
// We also output a "Depth" vector containing the z and w coordinates of each triangle in camera-space
struct VSOutput
{
	float4 Position : POSITION0;
	float2 Depth : TEXCOORD0;
};

// Pixel-shader input
struct PSInput
{
	float2 Depth : TEXCOORD0;
};

// Pixel-shader output
// We must ALWAYS output float4 from the pixel-shader regardless of what type 
// of render target (if any) we specify in XNA.
struct PSOutput
{
	float4 Depth : COLOR;
};

VSOutput VSFunction(VSInput input)
{
	VSOutput output;

	output.Position = mul(input.Position, WVP);

	output.Depth.xy = output.Position.zw;
  
	return output;
}

PSOutput PSFunction(PSInput input)
{
	PSOutput ret;
	float depth = input.Depth.x / input.Depth.y;
	ret.Depth = float4(depth, 0, 0, 0);
	return ret;
}

technique Depth
{
	pass Depth
	{
		VertexShader = compile vs_3_0 VSFunction();
		PixelShader = compile ps_3_0 PSFunction();
	}
}